import React, { Component } from 'react';

export default class Footer extends Component {
  clearAllFull = () => {
    this.props.delTodoAll()
  }
  checkAllChange = (e) => {
    const {checkAll} = this.props
    checkAll(e.target.checked)
  }
  render() {
    const {todos} = this.props
    // 获取总数
    const total = todos.length
    // 累加已完成
    const fullDone = todos.reduce((pre, todo) => pre += (todo.done ? 1 : 0),0)
    return (
      <div className='todo-footer'>
        <label>
          <input type='checkbox' checked={fullDone === total && total !== 0 ? true : false} onChange={this.checkAllChange}/>
        </label>
        <span>
          <span>已完成{fullDone}</span> / 全部{total}
        </span>
        <button className='btn btn-danger' onClick={this.clearAllFull}>清除已完成任务</button>
      </div>
    );
  }
}
